package com.smalls.newvideotwo.utils;

import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class NetSpeed {
    public NetSpeed() {
    }

    public static long[] getSpeed(String dev) {
        long[] mTotal = new long[2];
        String path = "/proc/net/dev";
        String content = null;
        Object receive = null;
        Object transmit = null;
        BufferedReader br = null;

        try {
            br = new BufferedReader(new FileReader(path));

            String begin;
            while((begin = br.readLine()) != null) {
                if(begin.contains(dev)) {
                    content = begin;
                    break;
                }
            }
        } catch (FileNotFoundException var21) {
            var21.printStackTrace();
        } catch (IOException var22) {
            var22.printStackTrace();
        } finally {
            if(br != null) {
                try {
                    br.close();
                } catch (IOException var20) {
                    var20.printStackTrace();
                }
            }

        }

        if(content != null && !content.equals("")) {
            int var24 = content.indexOf(58);
            String tmp = null;
            tmp = content.substring(var24 + 1, content.length());
            String[] tmpArray = new String[16];
            int counter = 0;
            String[] array = tmp.split("\\ ");

            for(int i = 0; i < array.length; ++i) {
                if(array[i].length() > 0) {
                    if(counter > tmpArray.length) {
                        break;
                    }

                    tmpArray[counter] = array[i];
                    ++counter;
                }
            }

            mTotal[0] = Long.parseLong(tmpArray[0]);
            mTotal[1] = Long.parseLong(tmpArray[8]);
        }

        return mTotal;
    }
}